package ucuserslogic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"navi-mumbai/app/rpc/model/pg/usercenter"
	"navi-mumbai/app/rpc/usercenter/internal/svc"
	"navi-mumbai/app/rpc/usercenter/pb"
	"navi-mumbai/common/utils"
	"navi-mumbai/common/xerr"
)

type UpdateActivityConfigLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateActivityConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateActivityConfigLogic {
	return &UpdateActivityConfigLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 创建活动设置
func (l *UpdateActivityConfigLogic) UpdateActivityConfig(in *pb.UpdateActivityConfigReq) (*pb.UpdateActivityConfigResp, error) {
	defer utils.RecoverPanic()

	uf := usercenter.ActivityConfig{
		Id:            in.Id,
		Content:       in.Content,
		Object:        in.Object,
		Clickway:      in.ClickWay,
		Frequency:     in.Frequency,
		Times:         in.Times,
		NumPerOneTime: in.NumPerOneTime,
		JumpToPage:    in.JumpToPage,
		Status:        in.Status,
		Operate:       in.Operate,
	}

	err := l.svcCtx.ActivityConfigModel.Update(l.ctx, &uf)
	if err != nil {
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}
	return &pb.UpdateActivityConfigResp{}, nil
}
